{extend name="Public:base"/}

{block name="main"}
<style>
    .list-dot{ padding-bottom:10px}
    .list-dot li,.list-dot-othors li{padding:5px 0; border-bottom:1px dotted #c6dde0; font-family:"宋体"; color:#bbb; position:relative;_height:22px}
    .list-dot li span,.list-dot-othors li span{color:#004499}
    .list-dot li a.close span,.list-dot-othors li a.close span{display:none}
    .list-dot li a.close,.list-dot-othors li a.close{ background: url("/public/images/cross.png") no-repeat left 3px; display:block; width:16px; height:16px;position: absolute;outline:none;right:5px; bottom:5px}
    .list-dot li a.close:hover,.list-dot-othors li a.close:hover{background-position: left -46px}
    .list-dot-othors li{float:left;width:24%;overflow:hidden;}
</style>
{load href="__STATIC__/MyDate/WdatePicker.js"/}
{load href="__JS__/jquery.colorpicker.js"/}
{load href="__JS__/Sortable.min.js"/}
<script type="text/javascript" charset="utf-8" src="/public/static/neditor/neditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/public/static/neditor/neditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="/public/static/neditor/lang/zh-cn/zh-cn.js"></script>
<div class="box-info">
    <form id="myform" action="{:U($model_name.'/edit')}" method="post">
        <input type="hidden" name="TOKEN" value="{:session('TOKEN')}">


        {volist name="fields" id="r"}
        {if condition="!empty($r['status'])"}
        <div class="form-group row">
            <label class="col-md-2 text-right col-form-label">
                {if condition="$r['required']"}<span class="text-daner">*</span>{/if}{$r.name}
            </label>
            <div class="col-sm-8" id="box_{$r['field']}">
                {if condition="$r['type'] == 'images'"}
                <?php
$parseData = $form->images($r,'');

                $file_list = json_decode($vo[$r['field']], true);
                ?>
                <div class="card">
                    <div class="card-header">最多同时可以上传{$r['setup']['upload_maxnum']}张
                        <div class="float-right">
                            <a class="btn btn-sm btn-info" href="javascript:swfupload('{$r['field']}', '{$parseData['cenpic_auth']}', up_images);">图片上传</a>
                        </div>
                    </div>
                    <div class="card-body" style="padding: 0;">
                        <div id="{$r['field']}_images" class="imagesList">
                            {notempty name="file_list"}
                            {volist name="file_list" id="v"}
                            <div id="uplistd_{$i}">
                                <img src="{$v['filepath']}"/>
                                <input type="hidden" name="{$r['field']}[]" value="{$v['filepath']}" />
                                <div class="image_title">
                                    <input type="text" class="form-control" placeholder="注释" name="{$r['field']}_name[]" value="{$v['filename']}" />
                                </div>
                                <button type="button" onclick="remove_this('uplistd_{$i}');" class="close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                            {/volist}
                            {else/}
                            {/notempty}
                        </div>
                    </div>
                </div>

                <script>
                    Sortable.create(pics_images, {
                        handle: "img",
                        animation: 150
                    });
                </script>
                {else/}
                {$form->getform($r['type'],$r,$value='')}
                {/if}
            </div>
        </div>
        {/if}
        {/volist}

        <div class="form-actions">
            <input type="hidden" name="id" value="{$vo.id}">
            <input type="hidden" name="forward" value="{$_SERVER['HTTP_REFERER']}"/>
            <input type="submit" value="提交" class="btn btn-primary" />
            <input type="reset" value="重置" class="btn btn-primary"/>
        </div>
    </form>
</div>
{/block}

{block name="script"}

<script type="text/javascript">
$(document).ready(function() {
    $('#myform').ajaxForm({
        success:  complete,  // post-submit callback
        dataType: 'json'
    });
});

function complete(data){
    if (data.status == 1) {
        layer.msg(data.info, {
            icon: 1,
            time: 2000 //2秒关闭（如果不配置，默认是3秒）
        }, function(){
            window.location.href = "{$Think.cookie.__forward__}";
            return true;
        });
    } else {
        layer.msg(data.info, {
            icon: 2,
            time: 2000 //2秒关闭（如果不配置，默认是3秒）
        });
    }
}
String.prototype.replaceAll = function(s1, s2) {
    return this.replace(new RegExp(s1, "gm"), s2);
}
$(function() {
    $('#myform').on('click', '.datalist .add', function() {
        var $el = $(this).parent().parent();
        var $datalist = $('#myform .datalist');
        var num = $datalist.data('num');
        $el.after(rowStr.replaceAll('{num}', num));
        num++;
        $datalist.data('num',num);
    }).on('click', '.datalist .remove', function() {
        var $el = $(this).parent().parent();
        $el.remove();
    });
});
</script>

{/block}